using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Input.Touch;
using Microsoft.Xna.Framework.Media;


namespace Risiko.Menu
{
  public interface IStartMenu
  {
    event MenuEvent OnStartGame;
    event MenuEvent OnLoadGame;
  }

  public class StartMenu : BaseMenu, IStartMenu
  {

    protected SpriteBatch spriteBatch;
    private Button playBtn, loadBtn;

    public StartMenu(Game game)
      : base(game)
    {
      //TouchPanel.EnabledGestures = GestureType.Tap;
      background = game.Content.Load<Texture2D>(@"Images//Board//RisikoMap");
      bounds = new Rectangle(0, 0, 800, 480);
    }

    /// <summary>
    /// Allows the game component to perform any initialization it needs to before starting
    /// to run.  This is where it can query for any required services and load content.
    /// </summary>
    public override void Initialize()
    {

      spriteBatch = this.Game.Services.GetService(typeof(SpriteBatch)) as SpriteBatch;

      loadBtn = new Button() { texture = Game.Content.Load<Texture2D>("white_pixel"), isActive = true, bounds = new Rectangle(bounds.Left + 100, bounds.Center.Y + 100, 80, 40), color = Color.White, spriteFont = Game.Content.Load<SpriteFont>("small_font"), message = "Load", textColor = Color.Black, scale = 1 };
      AddButton(loadBtn, () =>
        {
          if (OnLoadGame != null)
            OnLoadGame();
        });

      playBtn = new Button() { texture = Game.Content.Load<Texture2D>("white_pixel"), isActive = true, bounds = new Rectangle(bounds.Center.X, bounds.Center.Y, 100, 100), color = Color.White, spriteFont = Game.Content.Load<SpriteFont>("small_font"), message = "Play", textColor = Color.Black, scale = 1 };
      AddButton(playBtn, () =>
      {
        if (OnStartGame != null)
          OnStartGame();
      });

      base.Initialize();
    }

    /// <summary>
    /// Allows the game component to update itself.
    /// </summary>
    /// <param name="gameTime">Provides a snapshot of timing values.</param>
    public override void Update(GameTime gameTime)
    {

      //buttons.RemoveAt(0);
      //playBtn.isActive = false;
      //AddButton(playBtn, () =>
      //{
      //  if (OnStartGame != null)
      //    OnStartGame();
      //});


      base.Update(gameTime);
    }

    public override void Draw(GameTime gameTime)
    {
      base.Draw(gameTime);

      spriteBatch.Begin();

      playBtn.DrawCenteredButton(spriteBatch);
      loadBtn.DrawCenteredButton(spriteBatch);

      spriteBatch.End();
    }


    public event MenuEvent OnStartGame;
    public event MenuEvent OnLoadGame;
  }
}
